#region Usings

using System;
using System.Linq;
using System.Reflection;
using KanbanBoard.Server.Command.DomainModel;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Linq;

#endregion

namespace KanbanBoard.Server.Command.Infrastructure.DataAccess {
    public class DataContext : IDisposable {
        private readonly ISession session;
        private readonly ITransaction transaction;

        public DataContext() {
            session = Database.Instance.OpenSession();
            transaction = session.BeginTransaction();
        }

        public T Get<T>(object id) where T : class {
            return session.Get<T>(id);
        }

        public void Save(object entity) {
            session.Save(entity);
        }

        public void Delete(object entity) {
            session.Delete(entity);
        }

        public void Dispose() {
            transaction.Commit();
            session.Close();
        }
    }
}